<template>
    <section>
        <el-row :gutter="40">
            <el-col :span="14">
        <sy-baselist
                ref="proschedule"
                editVue="./business/ProjectSchedule_Edit.vue"
                :filters="filters"
                listUrl="server/setting/Project.ashx?cmd=GetList"
                @onLoadRow="onLoadRow"
                :fixWhere="fixWhere"
                @current-change="onProjectChange"
                hideAdd
                hideDel
        >
            <el-table-column prop="FName" align="center"  header-align="center" label="工程名称"  width="400" >
            </el-table-column>
            <template  slot="extendbtn_end" scope="props">
                <el-button size="small"  style="margin-left: 0px;" @click="NowSchedule(props.row)">当前进度</el-button>
            </template>
        </sy-baselist>
            </el-col>
            <el-col :span="9">
                <sy-baselist
                        ref="prodaily"
                        title="每日进度"
                        editVue="./business/ProjectDaily_Edit.vue"
                        deleteUrl="server/business/Daily.ashx?cmd=Delete"
                        listUrl="server/business/Daily.ashx?cmd=GetList"
                        @onLoadRow="onLoaddaliyRow"
                        :fixWhere="fixWhere"
                        @beforeAdd="beforeAddDaily"
                        :autoSearch="false"
                >
                    <el-table-column prop="FDate" align="center"  header-align="center" label="日期"  width="200" >
                    </el-table-column>
                    <template  scope="props" slot="extendbtn">
                        <el-button size="small" v-if="props.row.FStatus==0"  style="margin-left: 0px;" @click="DailySure(props.row)">确认</el-button>
                    </template>
                </sy-baselist>
            </el-col>
        </el-row>
        <nowschedule ref="nowschedule"></nowschedule>
    </section>
</template>

<script>
    import util from '../../common/util'
    import nowschedule from './ProjectSchedule_Now.vue'
    export default {
        components:{
            nowschedule
        },
        data(){
            return {
                fixWhere:'',
                filters:[],
                FProjectID:0
            }
        },
        methods:{
            onLoadRow(row)
            {
                 row.editTitle='设计目标录入'
            },
            onLoaddaliyRow(row){
                row.FDate = util.date.format(row.FDate,'yyyy-MM-dd')
                if(row.FStatus!=0){
                    row.hideDeleteBtn=true;
                    row.editTitle = '查看'
                }
            },
            init(){
                this.filters=[
                    {type: "string",name:"FName",text:"工程名称", value: ""}
                   ]
            },
            onProjectChange(row,oldRow){
                if(row) {
                    this.FProjectID = row.FID;
                    this.ProjectName = row.FName;
                    this.$refs.prodaily._search("FProjectID=" + row.FID);
                }
            },
            beforeAddDaily(row,r){
                if(this.FProjectID==0) {
                    return r.error = "请先选择项目";
                }
                row.FProjectID = this.FProjectID
                row.ProjectName = this.ProjectName
            },
            DailySure(row){
                util.post("server/business/Daily.ashx?cmd=Sure",row,this.switchLoading,result=> {
                    util.msgSuc("确认成功")
                    this.$refs.prodaily._refrash()
                })
            },
            NowSchedule(row){
                this.$refs['nowschedule']._openEdit(row)
            }
        },
        watch: {
            '$route' (to, from) {
                // 对路由变化作出响应...
                this.init()
            }
        },
        created(){
            this.init()
       }
    }
</script>